package com.share.trigger.http;

import com.share.domain.activity.repository.IActivityRepository;
import com.share.trigger.api.dto.IUserService;
import com.share.trigger.api.dto.Raffle.AddUserDTO;
import com.share.types.enums.ResponseCode;
import com.share.types.model.Response;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@Slf4j
@RestController
@CrossOrigin(origins = "*")
@RequestMapping("/api/${app.config.api-version}/raffle/user")
public class UserController implements IUserService {

    @Resource
    private IActivityRepository activityRepository;

    @RequestMapping(value = "add_user", method = RequestMethod.POST)
    @Override
    public Response<Boolean> addUser(@RequestBody AddUserDTO addUserDTO) {
        try {
            activityRepository.addUser(addUserDTO.getUserId(), addUserDTO.getActivityId());
            return Response.<Boolean>builder()
                    .code(ResponseCode.SUCCESS.getCode())
                    .info(ResponseCode.SUCCESS.getInfo())
                    .build();
        }catch (Exception e){
            return Response.<Boolean>builder()
                    .code(ResponseCode.UN_ERROR.getCode())
                    .info(ResponseCode.UN_ERROR.getInfo())
                    .build();
        }

    }

}
